﻿//-----------------------------------------------------------------------
// <copyright file="RegistryHelper.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation.
// All rights reserved.
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
// This code released under the terms of the 
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)
// </copyright>
// <author>Yogesh M Joshi</author>
// <email>ymjoshi@live.com</email>
// <date>16-May-2011</date>
//-----------------------------------------------------------------------

namespace SmartTag.Common.Utility
{
    using System;
    using Microsoft.Win32;

    /// <summary>
    /// Contains functions for windows registry interaction
    /// </summary>
    internal static class RegistryHelper
    {
        /// <summary>
        /// Reads the specific value from registry
        /// </summary>
        /// <param name="keyName">Name of the key</param>
        /// <param name="name">Name of the value if any</param>
        /// <returns>Value retrived</returns>
        public static string ReadStringValueFromLocalMachine(string keyName, string name)
        {
            string value = string.Empty;
            try
            {
                RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(keyName);
                if (registryKey != null)
                {
                    value = registryKey.GetValue(name) as string;
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "Error occured in ReadStringValueFromLocalMachine", (int)TraceLogEventId.ReadStringValueFromLocalMachine);
            }

            return value;
        }
    }
}
